package cn.edu.scau.cmi.chenmiaopeng.controller.factory;
import java.io.IOException;

import cn.edu.scau.cmi.chenmiaopeng.singleton.Chairman;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.stage.Stage;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.AnchorPane;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;

public class FactoryTypeController {
	@FXML
	private AnchorPane mainPane;
	@FXML
    private Button simple_button;
	@FXML
    private Button factory_button;
	@FXML
    private Button abstract_button;
//	public void setMainPain(AnchorPane mainPain) {
//		this.mainPane = mainPane;
//	}
	@FXML
    public void clickButton(ActionEvent e) {  //createInstance()
//		System.out.println(e.getSource());
//		System.out.println(e.toString());
		Object obj = e.getSource();
	    if(obj==simple_button) {
	    	//显示简单工厂方法
	    	System.out.println("简单工厂");
	    	try {
	    	Stage simpleStage = new Stage();
	    	
	    	FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/chenmiaopeng/ui/factory/simpleFactoryUI.fxml"));
	    	
	    	Parent root = loader.load();

			Scene scene = new Scene(root,497,458);
			
			ObservableList<String> options = FXCollections.observableArrayList("please choose meat:","Pork","Chicken","Beef");
			
			ComboBox<String> comboBox = (ComboBox<String>)loader.getNamespace().get("comboBox");

			comboBox.setItems(options);
			comboBox.getSelectionModel().select(0);
			simpleStage.setScene(scene);
			simpleStage.showAndWait();
	    	}
	    	catch(IOException ex) {
	    		ex.printStackTrace();
	    	}
	    }
	    else if(e.getSource()==factory_button) {
	    	//显示工厂方法
//	    	System.out.println("工厂方法");
	    	try {
		    	Stage simpleStage = new Stage();
		    	
		    	FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/chenmiaopeng/ui/factory/commonFactory.fxml"));
		    	
		    	Parent root = loader.load();

				Scene scene = new Scene(root,497,458);
				
				ObservableList<String> options = FXCollections.observableArrayList("please choose meat:","Pork","Chicken","Beef");
				ObservableList<String> options_buy =  FXCollections.observableArrayList("yes","no");
				ComboBox<String> comboBox = (ComboBox<String>)loader.getNamespace().get("comboBox");
				ComboBox<String> comboBox_buy = (ComboBox<String>)loader.getNamespace().get("comboBox1");
				comboBox.setItems(options);
				comboBox_buy.setItems(options_buy);
				comboBox.getSelectionModel().select(0);
				//
				simpleStage.setScene(scene);
				simpleStage.showAndWait();
		    	}
		    	catch(IOException ex) {
		    		ex.printStackTrace();
		    	}
	    }
	    else if(e.getSource()==abstract_button) {
	    	//显示抽象工厂方法
//	    	System.out.println("抽象工厂方法");
	    	try {
		    	Stage simpleStage = new Stage();
		    	
		    	FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/chenmiaopeng/ui/factory/abstractFactory.fxml"));
		    	
		    	Parent root = loader.load();

				Scene scene = new Scene(root,550,460);
				
				ObservableList<String> options = FXCollections.observableArrayList("please choose meat:","Pork","Chicken","Beef");
				ObservableList<String> options_brand =  FXCollections.observableArrayList("please choose brand:","Aonong","Tianbang","Wens");
				ObservableList<String> options_buy =  FXCollections.observableArrayList("yes","no");
				ComboBox<String> comboBox = (ComboBox<String>)loader.getNamespace().get("comboBox");
				ComboBox<String> comboBox_brand = (ComboBox<String>)loader.getNamespace().get("comboBox2");
				ComboBox<String> comboBox_buy = (ComboBox<String>)loader.getNamespace().get("comboBox1");
				comboBox.setItems(options);
				comboBox_brand.setItems(options_brand);
				comboBox_buy.setItems(options_buy);
				comboBox.getSelectionModel().select(0);
				comboBox_brand.getSelectionModel().selectFirst();
				//
				simpleStage.setScene(scene);
				simpleStage.showAndWait();
		    	}
		    	catch(IOException ex) {
		    		ex.printStackTrace();
		    	}
	    }


	}
}

//FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmi/chenmiaopeng/factory/ui/simpleFactoryUI.fxml"));
//pane = (AnchorPane)root.lookup("#anchorPane");
//mainPane.setVisible(false);